//
//  ViewController.m
//  14-UICollectionView
//
//  Created by 王道林 on 16/8/2.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    //1. UIcollectionview
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    // itemSize 默认大小 50  , 50
    layout.itemSize = CGSizeMake(CGRectGetWidth(self.view.bounds)  / 2 - 50, 120);
    
//    layout.itemSize = CGSizeMake(120, 120);
    // 滚动方向....滚动方向改变,, 会交换行和列;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //最小行间距
    layout.minimumLineSpacing = 10;
    // 最小列间距
//    layout.minimumInteritemSpacing = 0
    
    //分区的边距
    layout.sectionInset = 
    UIEdgeInsetsMake(20, 5, 20, 5);
    
    // 区头大小
    layout.headerReferenceSize = CGSizeMake(100, 100);
    
    //ios9 之后 区头的悬浮效果
    layout.sectionHeadersPinToVisibleBounds = YES;
    
    UICollectionView *myCollectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    [self.view addSubview:myCollectionView];
    myCollectionView.delegate = self;
    myCollectionView.dataSource = self;
    
    [myCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"wang"];
    // 头部的注册
    [myCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"wangdao"];
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 2;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"wang" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    
    return cell;
}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"wangdao" forIndexPath:indexPath];
    reusable.backgroundColor = [UIColor blueColor];
    return reusable;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
